/**
 * 学历提升积分管理初始化
 */
var DegreeTrainPoints = {
    id: "DegreeTrainPointsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    width: '900px',
    height: '620px'
};

/**
 * 初始化表格的列
 */
DegreeTrainPoints.initColumn = function () {
    return [
        {field: 'selectItem', radio: false},
            {title: '主键ID', field: 'id', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '年度', field: 'year', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '员工编号', field: 'empCode', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '员工姓名', field: 'empName', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '就读院校', field: 'school', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '所学专业', field: 'major', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '学历层次', field: 'education', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '学历层次代码', field: 'educationCode', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '学位', field: 'degree', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '学位代码', field: 'degreeCode', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '学习形式', field: 'learnType', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '学习形式代码', field: 'learnTypeCode', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '入学时间', field: 'strEnrolDate', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '毕业时间', field: 'strGraduationDate', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '证书编码', field: 'certificateCode', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '获得积分', field: 'integral', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '创建时间', field: 'createDate', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '数据来源', field: 'dataOrigin', visible: false, align: 'center', valign: 'middle',sortable: true}
    ];
};

/**
 * 检查是否选中
 */
DegreeTrainPoints.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        DegreeTrainPoints.seItem = selected[0];
        return true;
    }
};

DegreeTrainPoints.checks = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        DegreeTrainPoints.seItem = selected;
        return true;
    }
};
/**
 * 点击添加学历提升积分
 */
DegreeTrainPoints.openAddDegreeTrainPoints = function () {
    var index = layer.open({
        type: 2,
        title: '添加学历提升积分',
        area: [DegreeTrainPoints.width, DegreeTrainPoints.height], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/degreeTrainPoints/degreeTrainPoints_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看学历提升积分详情
 */
DegreeTrainPoints.openDegreeTrainPointsDetail = function () {
    if (this.check()) {
        var selected = $('#' + this.id).bootstrapTable('getSelections');
        if(selected.length > 1){
            Feng.info("修改只能选择一条数据！");
            return false;
        }
        var index = layer.open({
            type: 2,
            title: '学历提升积分详情',
            area: [DegreeTrainPoints.width, DegreeTrainPoints.height], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/degreeTrainPoints/degreeTrainPoints_update/' + DegreeTrainPoints.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除学历提升积分
 */
DegreeTrainPoints.delete = function () {
    if (this.checks()) {
        var operation = function() {
            var ajax = new $ax(Feng.ctxPath + "/degreeTrainPoints/delete", function (data) {
                Feng.success("删除成功!");
                DegreeTrainPoints.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            var ids = "";
            for (var i in DegreeTrainPoints.seItem) {
                if (!ids) {
                    ids += DegreeTrainPoints.seItem[i].id;
                } else {
                    ids += "," + DegreeTrainPoints.seItem[i].id;
                }
            }
            ajax.set("degreeTrainPointsId", ids);
            ajax.start();
        };
        Feng.confirm("是否删除选中的"+DegreeTrainPoints.seItem.length +"数据？", operation);

    }
};

/**
 * 查询学历提升积分列表
 */
DegreeTrainPoints.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    DegreeTrainPoints.table.refresh({query: queryData});
};

/**
 * 打开导入学历提升积分数据页面
 */
DegreeTrainPoints.import = function () {
    var index = layer.open({
        type: 2,
        title: '学历提升积分',
        area: ['600px', '500px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/degreeTrainPoints/degreeTrainPoints_import'
    });
    this.layerIndex = index;
    layer.full(index);
};

/**
 * 高级搜索
 */
DegreeTrainPoints.g_search = function () {
    var index = layer.open({
        type: 2,
        skin: 'layui-layer-molv',
        title: '高级搜索',
        area: ['800px', '300px'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/employee/g_search',
        btn: ['确定','关闭'],
        yes: function(index, layero){
            var queryData = window["layui-layer-iframe" + index].Employee.search2();

            DegreeTrainPoints.table.setQueryParams(queryData);
            DegreeTrainPoints.table.refresh();
            DegreeTrainPoints.table.empty();
            layer.close(index); //如果设定了yes回调，需进行手工关闭
        }
    });
    this.layerIndex = index;
};

DegreeTrainPoints.export = function(){
    window.open(Feng.ctxPath + '/degreeTrainPoints/export',"_parent");
    Feng.success("导出成功!");
};

$(function () {
    var defaultColunms = DegreeTrainPoints.initColumn();
    var table = new BSTable(DegreeTrainPoints.id, "/degreeTrainPoints/list", defaultColunms);
    table.setPaginationType("client");
    DegreeTrainPoints.table = table.init();
});
